/*   1:    */ package com.sie.driver.ftusbdriver;
/*   2:    */ 
/*   3:    */ class FT_EE_4232H_Ctrl
/*   4:    */   extends FT_EE_Ctrl
/*   5:    */ {
/*   6:    */   private static final byte EEPROM_SIZE_LOCATION = 12;
/*   7:    */   private static final String DEFAULT_PID = "6011";
/*   8:    */   private static final int AL_DRIVE_CURRENT = 3;
/*   9:    */   private static final int AH_DRIVE_CURRENT = 48;
/*  10:    */   private static final int BL_DRIVE_CURRENT = 768;
/*  11:    */   private static final int BH_DRIVE_CURRENT = 12288;
/*  12:    */   private static final int AL_FAST_SLEW = 4;
/*  13:    */   private static final int AL_SCHMITT_INPUT = 8;
/*  14:    */   private static final int AH_FAST_SLEW = 64;
/*  15:    */   private static final int AH_SCHMITT_INPUT = 128;
/*  16:    */   private static final int BL_FAST_SLEW = 1024;
/*  17:    */   private static final int BL_SCHMITT_INPUT = 2048;
/*  18:    */   private static final int BH_FAST_SLEW = 16384;
/*  19:    */   private static final int BH_SCHMITT_INPUT = 32768;
/*  20:    */   private static final int TPRDRV = 24;
/*  21:    */   private static final int AL_TXDEN = 4096;
/*  22:    */   private static final int AH_TXDEN = 8192;
/*  23:    */   private static final int BL_TXDEN = 16384;
/*  24:    */   private static final int BH_TXDEN = 32768;
/*  25:    */   
/*  26:    */   FT_EE_4232H_Ctrl(FT_Device usbC)
/*  27:    */     throws D2xxManager.D2xxException
/*  28:    */   {
/*  29: 33 */     super(usbC);
/*  30: 34 */     getEepromSize((byte)12);
/*  31:    */   }
/*  32:    */   
/*  33:    */   short programEeprom(FT_EEPROM ee)
/*  34:    */   {
/*  35: 40 */     int[] dataToWrite = new int[this.mEepromSize];
/*  36: 42 */     if (ee.getClass() != FT_EEPROM_4232H.class) {
/*  37: 43 */       return 1;
/*  38:    */     }
/*  39: 45 */     FT_EEPROM_4232H eeprom = (FT_EEPROM_4232H)ee;
/*  40:    */     try
/*  41:    */     {
/*  42: 52 */       dataToWrite[0] = 0;
/*  43: 53 */       if (eeprom.AL_LoadVCP) {
/*  44: 54 */         dataToWrite[0] |= 0x8;
/*  45:    */       }
/*  46: 55 */       if (eeprom.BL_LoadVCP) {
/*  47: 56 */         dataToWrite[0] |= 0x80;
/*  48:    */       }
/*  49: 57 */       if (eeprom.AH_LoadVCP) {
/*  50: 58 */         dataToWrite[0] |= 0x800;
/*  51:    */       }
/*  52: 59 */       if (eeprom.BH_LoadVCP) {
/*  53: 60 */         dataToWrite[0] |= 0x8000;
/*  54:    */       }
/*  55: 65 */       dataToWrite[1] = eeprom.VendorId;
/*  56:    */       
/*  57:    */ 
/*  58:    */ 
/*  59:    */ 
/*  60: 70 */       dataToWrite[2] = eeprom.ProductId;
/*  61:    */       
/*  62:    */ 
/*  63:    */ 
/*  64:    */ 
/*  65: 75 */       dataToWrite[3] = 2048;
/*  66:    */       
/*  67:    */ 
/*  68:    */ 
/*  69:    */ 
/*  70: 80 */       dataToWrite[4] = setUSBConfig(ee);
/*  71:    */       
/*  72:    */ 
/*  73:    */ 
/*  74:    */ 
/*  75: 85 */       dataToWrite[5] = setDeviceControl(ee);
/*  76: 87 */       if (eeprom.AL_LoadRI_RS485) {
/*  77: 88 */         dataToWrite[5] = ((short)(dataToWrite[5] | 0x1000));
/*  78:    */       }
/*  79: 89 */       if (eeprom.AH_LoadRI_RS485) {
/*  80: 90 */         dataToWrite[5] = ((short)(dataToWrite[5] | 0x2000));
/*  81:    */       }
/*  82: 91 */       if (eeprom.BL_LoadRI_RS485) {
/*  83: 92 */         dataToWrite[5] = ((short)(dataToWrite[5] | 0x4000));
/*  84:    */       }
/*  85: 93 */       if (eeprom.BH_LoadRI_RS485) {
/*  86: 94 */         dataToWrite[5] = ((short)(dataToWrite[5] | 0x8000));
/*  87:    */       }
/*  88: 99 */       dataToWrite[6] = 0;
/*  89:100 */       short driveA = eeprom.AL_DriveCurrent;
/*  90:101 */       if (driveA == -1) {
/*  91:101 */         driveA = 0;
/*  92:    */       }
/*  93:102 */       dataToWrite[6] |= driveA;
/*  94:103 */       if (eeprom.AL_SlowSlew) {
/*  95:104 */         dataToWrite[6] |= 0x4;
/*  96:    */       }
/*  97:105 */       if (eeprom.AL_SchmittInput) {
/*  98:106 */         dataToWrite[6] |= 0x8;
/*  99:    */       }
/* 100:108 */       short driveB = eeprom.AH_DriveCurrent;
/* 101:109 */       if (driveB == -1) {
/* 102:109 */         driveB = 0;
/* 103:    */       }
/* 104:110 */       driveB = (short)(driveB << 4);
/* 105:111 */       dataToWrite[6] |= driveB;
/* 106:112 */       if (eeprom.AH_SlowSlew) {
/* 107:113 */         dataToWrite[6] |= 0x40;
/* 108:    */       }
/* 109:114 */       if (eeprom.AH_SchmittInput) {
/* 110:115 */         dataToWrite[6] |= 0x80;
/* 111:    */       }
/* 112:117 */       short driveC = eeprom.BL_DriveCurrent;
/* 113:118 */       if (driveC == -1) {
/* 114:118 */         driveC = 0;
/* 115:    */       }
/* 116:119 */       driveC = (short)(driveC << 8);
/* 117:120 */       dataToWrite[6] |= driveC;
/* 118:121 */       if (eeprom.BL_SlowSlew) {
/* 119:122 */         dataToWrite[6] |= 0x400;
/* 120:    */       }
/* 121:123 */       if (eeprom.BL_SchmittInput) {
/* 122:124 */         dataToWrite[6] |= 0x800;
/* 123:    */       }
/* 124:126 */       short driveD = eeprom.BH_DriveCurrent;
/* 125:127 */       driveD = (short)(driveD << 12);
/* 126:128 */       dataToWrite[6] |= driveD;
/* 127:129 */       if (eeprom.BH_SlowSlew) {
/* 128:130 */         dataToWrite[6] |= 0x4000;
/* 129:    */       }
/* 130:131 */       if (eeprom.BH_SchmittInput) {
/* 131:132 */         dataToWrite[6] |= 0x8000;
/* 132:    */       }
/* 133:137 */       boolean eeprom46 = false;
/* 134:138 */       int offset = 77;
/* 135:139 */       if (this.mEepromType == 70)
/* 136:    */       {
/* 137:141 */         offset = 13;
/* 138:142 */         eeprom46 = true;
/* 139:    */       }
/* 140:145 */       offset = setStringDescriptor(eeprom.Manufacturer, dataToWrite, offset, 7, eeprom46);
/* 141:    */       
/* 142:    */ 
/* 143:    */ 
/* 144:    */ 
/* 145:150 */       offset = setStringDescriptor(eeprom.Product, dataToWrite, offset, 8, eeprom46);
/* 146:155 */       if (eeprom.SerNumEnable) {
/* 147:156 */         offset = setStringDescriptor(eeprom.SerialNumber, dataToWrite, offset, 9, eeprom46);
/* 148:    */       }
/* 149:161 */       switch (eeprom.TPRDRV)
/* 150:    */       {
/* 151:    */       case 0: 
/* 152:164 */         dataToWrite[11] = 0;
/* 153:165 */         break;
/* 154:    */       case 1: 
/* 155:167 */         dataToWrite[11] = 8;
/* 156:168 */         break;
/* 157:    */       case 2: 
/* 158:170 */         dataToWrite[11] = 16;
/* 159:171 */         break;
/* 160:    */       case 3: 
/* 161:173 */         dataToWrite[11] = 24;
/* 162:174 */         break;
/* 163:    */       default: 
/* 164:176 */         dataToWrite[11] = 0;
/* 165:    */       }
/* 166:183 */       dataToWrite[12] = this.mEepromType;
/* 167:188 */       if ((dataToWrite[1] != 0) && (dataToWrite[2] != 0))
/* 168:    */       {
/* 169:190 */         boolean returnCode = false;
/* 170:191 */         returnCode = programEeprom(dataToWrite, this.mEepromSize - 1);
/* 171:192 */         if (returnCode) {
/* 172:193 */           return 0;
/* 173:    */         }
/* 174:195 */         return 1;
/* 175:    */       }
/* 176:199 */       return 2;
/* 177:    */     }
/* 178:    */     catch (Exception e)
/* 179:    */     {
/* 180:204 */       e.printStackTrace();
/* 181:    */     }
/* 182:206 */     return 0;
/* 183:    */   }
/* 184:    */   
/* 185:    */   FT_EEPROM readEeprom()
/* 186:    */   {
/* 187:212 */     FT_EEPROM_4232H eeprom = new FT_EEPROM_4232H();
/* 188:213 */     int[] data = new int[this.mEepromSize];
/* 189:215 */     if (this.mEepromBlank) {
/* 190:218 */       return eeprom;
/* 191:    */     }
/* 192:    */     try
/* 193:    */     {
/* 194:223 */       for (short i = 0; i < this.mEepromSize; i = (short)(i + 1)) {
/* 195:224 */         data[i] = readWord(i);
/* 196:    */       }
/* 197:231 */       short data3x00 = (short)((data[0] & 0x8) >> 3);
/* 198:232 */       if (data3x00 == 1)
/* 199:    */       {
/* 200:233 */         eeprom.AL_LoadVCP = true;
/* 201:234 */         eeprom.AL_LoadD2XX = false;
/* 202:    */       }
/* 203:    */       else
/* 204:    */       {
/* 205:237 */         eeprom.AL_LoadVCP = false;
/* 206:238 */         eeprom.AL_LoadD2XX = true;
/* 207:    */       }
/* 208:242 */       short data7x00 = (short)((data[0] & 0x80) >> 7);
/* 209:243 */       if (data7x00 == 1)
/* 210:    */       {
/* 211:244 */         eeprom.BL_LoadVCP = true;
/* 212:245 */         eeprom.BL_LoadD2XX = false;
/* 213:    */       }
/* 214:    */       else
/* 215:    */       {
/* 216:248 */         eeprom.BL_LoadVCP = false;
/* 217:249 */         eeprom.BL_LoadD2XX = true;
/* 218:    */       }
/* 219:253 */       short data11x00 = (short)((data[0] & 0x800) >> 11);
/* 220:254 */       if (data11x00 == 1)
/* 221:    */       {
/* 222:255 */         eeprom.AH_LoadVCP = true;
/* 223:256 */         eeprom.AH_LoadD2XX = false;
/* 224:    */       }
/* 225:    */       else
/* 226:    */       {
/* 227:259 */         eeprom.AH_LoadVCP = false;
/* 228:260 */         eeprom.AH_LoadD2XX = true;
/* 229:    */       }
/* 230:264 */       short data15x00 = (short)((data[0] & 0x8000) >> 15);
/* 231:265 */       if (data15x00 == 1)
/* 232:    */       {
/* 233:266 */         eeprom.BH_LoadVCP = true;
/* 234:267 */         eeprom.BH_LoadD2XX = false;
/* 235:    */       }
/* 236:    */       else
/* 237:    */       {
/* 238:270 */         eeprom.BH_LoadVCP = false;
/* 239:271 */         eeprom.BH_LoadD2XX = true;
/* 240:    */       }
/* 241:277 */       eeprom.VendorId = ((short)data[1]);
/* 242:    */       
/* 243:    */ 
/* 244:    */ 
/* 245:    */ 
/* 246:282 */       eeprom.ProductId = ((short)data[2]);
/* 247:    */       
/* 248:    */ 
/* 249:    */ 
/* 250:    */ 
/* 251:    */ 
/* 252:    */ 
/* 253:    */ 
/* 254:    */ 
/* 255:    */ 
/* 256:    */ 
/* 257:293 */       getUSBConfig(eeprom, data[4]);
/* 258:    */       
/* 259:    */ 
/* 260:    */ 
/* 261:    */ 
/* 262:298 */       getDeviceControl(eeprom, data[5]);
/* 263:300 */       if ((data[5] & 0x1000) == 4096) {
/* 264:301 */         eeprom.AL_LoadRI_RS485 = true;
/* 265:    */       }
/* 266:302 */       if ((data[5] & 0x2000) == 8192) {
/* 267:303 */         eeprom.AH_LoadRI_RS485 = true;
/* 268:    */       }
/* 269:304 */       if ((data[5] & 0x4000) == 16384) {
/* 270:305 */         eeprom.AH_LoadRI_RS485 = true;
/* 271:    */       }
/* 272:306 */       if ((data[5] & 0x8000) == 32768) {
/* 273:307 */         eeprom.AH_LoadRI_RS485 = true;
/* 274:    */       }
/* 275:313 */       short data01x06 = (short)(data[6] & 0x3);
/* 276:315 */       switch (data01x06)
/* 277:    */       {
/* 278:    */       case 0: 
/* 279:317 */         eeprom.AL_DriveCurrent = 0;
/* 280:318 */         break;
/* 281:    */       case 1: 
/* 282:320 */         eeprom.AL_DriveCurrent = 1;
/* 283:321 */         break;
/* 284:    */       case 2: 
/* 285:323 */         eeprom.AL_DriveCurrent = 2;
/* 286:324 */         break;
/* 287:    */       case 3: 
/* 288:326 */         eeprom.AL_DriveCurrent = 3;
/* 289:327 */         break;
/* 290:    */       }
/* 291:332 */       short data2x06 = (short)(data[6] & 0x4);
/* 292:333 */       if (data2x06 == 4) {
/* 293:334 */         eeprom.AL_SlowSlew = true;
/* 294:    */       } else {
/* 295:337 */         eeprom.AL_SlowSlew = false;
/* 296:    */       }
/* 297:340 */       short data3x06 = (short)(data[6] & 0x8);
/* 298:341 */       if (data3x06 == 8) {
/* 299:342 */         eeprom.AL_SchmittInput = true;
/* 300:    */       } else {
/* 301:344 */         eeprom.AL_SchmittInput = false;
/* 302:    */       }
/* 303:347 */       short data45x06 = (short)((data[6] & 0x30) >> 4);
/* 304:349 */       switch (data45x06)
/* 305:    */       {
/* 306:    */       case 0: 
/* 307:351 */         eeprom.AH_DriveCurrent = 0;
/* 308:352 */         break;
/* 309:    */       case 1: 
/* 310:354 */         eeprom.AH_DriveCurrent = 1;
/* 311:355 */         break;
/* 312:    */       case 2: 
/* 313:357 */         eeprom.AH_DriveCurrent = 2;
/* 314:358 */         break;
/* 315:    */       case 3: 
/* 316:360 */         eeprom.AH_DriveCurrent = 3;
/* 317:361 */         break;
/* 318:    */       }
/* 319:366 */       short data6x06 = (short)(data[6] & 0x40);
/* 320:367 */       if (data6x06 == 64) {
/* 321:368 */         eeprom.AH_SlowSlew = true;
/* 322:    */       } else {
/* 323:371 */         eeprom.AH_SlowSlew = false;
/* 324:    */       }
/* 325:374 */       short data7x06 = (short)(data[6] & 0x80);
/* 326:375 */       if (data7x06 == 128) {
/* 327:376 */         eeprom.AH_SchmittInput = true;
/* 328:    */       } else {
/* 329:378 */         eeprom.AH_SchmittInput = false;
/* 330:    */       }
/* 331:381 */       short data89X06 = (short)((data[6] & 0x300) >> 8);
/* 332:383 */       switch (data89X06)
/* 333:    */       {
/* 334:    */       case 0: 
/* 335:385 */         eeprom.BL_DriveCurrent = 0;
/* 336:386 */         break;
/* 337:    */       case 1: 
/* 338:388 */         eeprom.BL_DriveCurrent = 1;
/* 339:389 */         break;
/* 340:    */       case 2: 
/* 341:391 */         eeprom.BL_DriveCurrent = 2;
/* 342:392 */         break;
/* 343:    */       case 3: 
/* 344:394 */         eeprom.BL_DriveCurrent = 3;
/* 345:395 */         break;
/* 346:    */       }
/* 347:400 */       short data10x06 = (short)(data[6] & 0x400);
/* 348:401 */       if (data10x06 == 1024) {
/* 349:402 */         eeprom.BL_SlowSlew = true;
/* 350:    */       } else {
/* 351:405 */         eeprom.BL_SlowSlew = false;
/* 352:    */       }
/* 353:408 */       short data11x06 = (short)(data[6] & 0x800);
/* 354:409 */       if (data11x06 == 2048) {
/* 355:410 */         eeprom.BL_SchmittInput = true;
/* 356:    */       } else {
/* 357:412 */         eeprom.BL_SchmittInput = false;
/* 358:    */       }
/* 359:415 */       short data1213X06 = (short)((data[6] & 0x3000) >> 12);
/* 360:417 */       switch (data1213X06)
/* 361:    */       {
/* 362:    */       case 0: 
/* 363:419 */         eeprom.BH_DriveCurrent = 0;
/* 364:420 */         break;
/* 365:    */       case 1: 
/* 366:422 */         eeprom.BH_DriveCurrent = 1;
/* 367:423 */         break;
/* 368:    */       case 2: 
/* 369:425 */         eeprom.BH_DriveCurrent = 2;
/* 370:426 */         break;
/* 371:    */       case 3: 
/* 372:428 */         eeprom.BH_DriveCurrent = 3;
/* 373:429 */         break;
/* 374:    */       }
/* 375:434 */       short data14x06 = (short)(data[6] & 0x4000);
/* 376:435 */       if (data14x06 == 16384) {
/* 377:436 */         eeprom.BH_SlowSlew = true;
/* 378:    */       } else {
/* 379:439 */         eeprom.BH_SlowSlew = false;
/* 380:    */       }
/* 381:442 */       short data15x06 = (short)(data[6] & 0x8000);
/* 382:443 */       if (data15x06 == 32768) {
/* 383:444 */         eeprom.BH_SchmittInput = true;
/* 384:    */       } else {
/* 385:446 */         eeprom.BH_SchmittInput = false;
/* 386:    */       }
/* 387:451 */       short datax0B = (short)((data[11] & 0x18) >> 3);
/* 388:452 */       if (datax0B < 4) {
/* 389:454 */         eeprom.TPRDRV = datax0B;
/* 390:    */       } else {
/* 391:457 */         eeprom.TPRDRV = 0;
/* 392:    */       }
/* 393:462 */       int addr = data[7] & 0xFF;
/* 394:464 */       if (this.mEepromType == 70)
/* 395:    */       {
/* 396:466 */         addr -= 128;
/* 397:467 */         addr /= 2;
/* 398:468 */         eeprom.Manufacturer = getStringDescriptor(addr, data);
/* 399:469 */         addr = data[8] & 0xFF;
/* 400:470 */         addr -= 128;
/* 401:471 */         addr /= 2;
/* 402:472 */         eeprom.Product = getStringDescriptor(addr, data);
/* 403:473 */         addr = data[9] & 0xFF;
/* 404:474 */         addr -= 128;
/* 405:475 */         addr /= 2;
/* 406:476 */         eeprom.SerialNumber = getStringDescriptor(addr, data);
/* 407:    */       }
/* 408:    */       else
/* 409:    */       {
/* 410:481 */         addr /= 2;
/* 411:482 */         eeprom.Manufacturer = getStringDescriptor(addr, data);
/* 412:483 */         addr = data[8] & 0xFF;
/* 413:484 */         addr /= 2;
/* 414:485 */         eeprom.Product = getStringDescriptor(addr, data);
/* 415:486 */         addr = data[9] & 0xFF;
/* 416:487 */         addr /= 2;
/* 417:488 */         eeprom.SerialNumber = getStringDescriptor(addr, data);
/* 418:    */       }
/* 419:500 */       return eeprom;
/* 420:    */     }
/* 421:    */     catch (Exception e) {}
/* 422:504 */     return null;
/* 423:    */   }
/* 424:    */   
/* 425:    */   int getUserSize()
/* 426:    */   {
/* 427:513 */     int data = readWord((short)9);
/* 428:514 */     int ptr = data & 0xFF;
/* 429:515 */     ptr /= 2;
/* 430:    */     
/* 431:    */ 
/* 432:518 */     int length = (data & 0xFF00) >> 8;
/* 433:519 */     ptr += length / 2;
/* 434:520 */     ptr++;
/* 435:    */     
/* 436:522 */     return (this.mEepromSize - 1 - 1 - ptr) * 2;
/* 437:    */   }
/* 438:    */   
/* 439:    */   int writeUserData(byte[] data)
/* 440:    */   {
/* 441:529 */     int dataWrite = 0;
/* 442:530 */     short offset = 0;
/* 443:532 */     if (data.length > getUserSize()) {
/* 444:533 */       return 0;
/* 445:    */     }
/* 446:535 */     int[] eeprom = new int[this.mEepromSize];
/* 447:536 */     for (short i = 0; i < this.mEepromSize; i = (short)(i + 1)) {
/* 448:537 */       eeprom[i] = readWord(i);
/* 449:    */     }
/* 450:540 */     offset = (short)(this.mEepromSize - getUserSize() / 2 - 1 - 1);
/* 451:542 */     for (int i = 0; i < data.length; i += 2)
/* 452:    */     {
/* 453:544 */       if (i + 1 < data.length) {
/* 454:545 */         dataWrite = data[(i + 1)] & 0xFF;
/* 455:    */       } else {
/* 456:547 */         dataWrite = 0;
/* 457:    */       }
/* 458:549 */       dataWrite <<= 8;
/* 459:550 */       dataWrite |= data[i] & 0xFF;
/* 460:    */       
/* 461:552 */       eeprom[(offset++)] = dataWrite;
/* 462:    */     }
/* 463:556 */     if ((eeprom[1] != 0) && (eeprom[2] != 0))
/* 464:    */     {
/* 465:558 */       boolean returnCode = false;
/* 466:559 */       returnCode = programEeprom(eeprom, this.mEepromSize - 1);
/* 467:560 */       if (!returnCode) {
/* 468:561 */         return 0;
/* 469:    */       }
/* 470:    */     }
/* 471:    */     else
/* 472:    */     {
/* 473:565 */       return 0;
/* 474:    */     }
/* 475:568 */     return data.length;
/* 476:    */   }
/* 477:    */   
/* 478:    */   byte[] readUserData(int length)
/* 479:    */   {
/* 480:574 */     byte Hi = 0;
/* 481:575 */     byte Lo = 0;
/* 482:576 */     int dataRead = 0;
/* 483:577 */     byte[] data = new byte[length];
/* 484:579 */     if ((length == 0) || (length > getUserSize())) {
/* 485:580 */       return null;
/* 486:    */     }
/* 487:582 */     short offset = (short)(this.mEepromSize - getUserSize() / 2 - 1 - 1);
/* 488:584 */     for (int i = 0; i < length; i += 2)
/* 489:    */     {
/* 490:586 */       dataRead = readWord(offset++);
/* 491:588 */       if (i + 1 < data.length)
/* 492:    */       {
/* 493:590 */         Hi = (byte)(dataRead & 0xFF);
/* 494:591 */         data[(i + 1)] = Hi;
/* 495:    */       }
/* 496:    */       else
/* 497:    */       {
/* 498:595 */         Lo = 0;
/* 499:    */       }
/* 500:597 */       Lo = (byte)((dataRead & 0xFF00) >> 8);
/* 501:598 */       data[i] = Lo;
/* 502:    */     }
/* 503:600 */     return data;
/* 504:    */   }
/* 505:    */ }



/* Location:           E:\code\demo\A108DevForBankComm\libs\d2xx.jar

 * Qualified Name:     com.ftdi.j2xx.FT_EE_4232H_Ctrl

 * JD-Core Version:    0.7.0.1

 */